package com.lun.swordtowardoffer2.c06;

import java.util.LinkedList;

public class DailyTemperatures {

	public int[] dailyTemperatures(int[] temperatures) {
		int[] waitDays = new int[temperatures.length];
		LinkedList<Integer> stack = new LinkedList<>(); 
		
		for(int i = 0; i < temperatures.length; i++) {
			while(!stack.isEmpty() && temperatures[i] > temperatures[stack.peek()]) {
				int top = stack.pop();
				waitDays[top] = i - top;
			}
			stack.push(i);
		}
		return waitDays;
	}

}
